package org.grapes.wine.api.server.method.impl;

import java.util.EnumSet;
import java.util.HashMap;

import org.apache.log4j.Logger;
import org.grapes.wine.api.bean.CheckAppBean;
import org.grapes.wine.api.method.EWineMethod;
import org.grapes.wine.api.server.exception.MethodException;
import org.grapes.wine.api.server.method.command.MethodCommand;

public class MethodList extends HashMap<EWineMethod, MethodCommand> {
	
	private static final long serialVersionUID = 1L;
	
	private static Logger logger = Logger.getLogger(MethodList.class);
	private static MethodList methodList = new MethodList();
	static {
		methodList.put(EWineMethod.GET_ADJOINED_LANDSCAPE_DISTANCE, new GetAdjoinedLandscapeDistance());
		methodList.put(EWineMethod.GET_ADJOINED_LANDSCAPE_LOCATION, new GetAdjoinedLandscapeLocation());
		methodList.put(EWineMethod.GET_ADJOINED_LANDSCAPE_PRICE, new GetAdjoinedLandscapePrice());
		methodList.put(EWineMethod.GET_ADJOINED_LANDSCAPE_TIME, new GetAdjoinedLandscapeTime());
		methodList.put(EWineMethod.GET_COSTOM_INTRODUCTION, new GetCostomIntroduction());
		methodList.put(EWineMethod.GET_COSTOM_RELATIVE_LANDSCAPE, new GetCostomRelativeLandscape());
		methodList.put(EWineMethod.GET_FEATURED_COURSE_INTRODUCTION, new GetFeaturedCourseIntroduction());
		methodList.put(EWineMethod.GET_FEATURED_COURSE_DAYSNUM, new GetFeaturedCourseDaySum());
		methodList.put(EWineMethod.GET_HOTELINFO_HOTEL_INTRODUCTION, new GetHotelInfoHotelIntroduction());
		methodList.put(EWineMethod.GET_LANDSCAPE_INTRODUCTION, new GetLandscapeIntroduction());
		methodList.put(EWineMethod.GET_LANDSCAPE_SERIAL, new GetLandscapeSerial());
		methodList.put(EWineMethod.GET_LANDSCAPE_SIGHTINVOLVED, new GetLandscapeSightInvolved());
		methodList.put(EWineMethod.GET_LANDSCAPE_TICKET_PRICE, new GetLandscapeTicketPrice());
		methodList.put(EWineMethod.GET_LANDSCAPE_VISIT_TIME, new GetLandscapeVisitTime());
		methodList.put(EWineMethod.GET_PATH2BYD_ROUTE, new GetPath2BYDRoute());
		methodList.put(EWineMethod.GET_YACHT_PRICE, new GetYachtPrice());
		methodList.put(EWineMethod.GET_YACHT_CAPACITY, new GetYachtCapacity());
		methodList.put(EWineMethod.SEARCH_ADJOINED_LANDSCAPE, new SearchAdjoinedLandscape());
		methodList.put(EWineMethod.SEARCH_COSTOM, new SearchCostom());
		methodList.put(EWineMethod.SEARCH_FEATURED_COURSE, new SearchFeaturedCourse());
		methodList.put(EWineMethod.SEARCH_HOTELINFO, new SearchHotelInfo());
		methodList.put(EWineMethod.SEARCH_LANDSCAPE, new SearchLandscape());
		methodList.put(EWineMethod.SEARCH_PATH2BYD, new SearchPath2BYD());
		methodList.put(EWineMethod.SEARCH_YACHT, new SearchYacht());
		methodList.put(EWineMethod.AUTH_CHECK_APP, new CheckApp());
		methodList.put(EWineMethod.AUTH_GET_USERID, new GetUserId());
	}
	
	public static MethodCommand getMethod(EWineMethod method) {
		try {
			if (methodNotFound(method))
				throw new MethodException();
			/*
			 * notice that you must get the String variable via methodList
			 */
			logger.info("methodFound: " + method);
			return methodList.get(method);
		} catch (MethodException we) {
			logger.info("Method not found");
			we.printStackTrace();
		}
		return null;
	}
	
	public static boolean methodNotFound(EWineMethod method) {
		EnumSet<EWineMethod> wineMethod = EWineMethod.postAuthMethods();
		return !wineMethod.contains(method);
	}
}
